package com.kyzh.core.pager.weal.video

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.google.android.material.tabs.TabLayoutMediator
import com.gushenge.atools.util.AView
import com.gushenge.atools.util.setMargins
import com.gushenge.core.base.fragment.BaseFragment
import com.gushenge.core.dao.MMKVConsts
import com.kyzh.core.R
import com.kyzh.core.adapters.VideoBaseAdapter
import com.shuyu.gsyvideoplayer.GSYVideoManager
import kotlinx.android.synthetic.main.fragment_video.*

class VideoFragment : BaseFragment() {



    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
                              savedInstanceState: Bundle?): View? {
        return inflater.inflate(R.layout.fragment_video, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        tabVideo.setMargins(0,AView.getStatusBarHeight(requireActivity()),0,0)
        val adapter = VideoBaseAdapter(this, arrayListOf(getString(R.string.recom),getString(R.string.attention)))
        viewPager.adapter = adapter
        viewPager.currentItem = 0
        val mediator = TabLayoutMediator(tabVideo,viewPager){ tab,position->
            tab.text = if (position==0) getString(R.string.recom) else getString(R.string.attention)
        }
        mediator.attach()

    }

    override fun onDestroyView() {
        super.onDestroyView()
    }

    override fun onHiddenChanged(hidden: Boolean) {
        super.onHiddenChanged(hidden)
        MMKVConsts.videoHidden = hidden
        GSYVideoManager.onPause()
    }

    override fun onResume() {
        super.onResume()
        GSYVideoManager.onPause()
    }
}